1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('AtomEntry', function(){ |
5
|
|
|
|
6
|
|
|
var json = { |
7
|
|
|
authors: [ |
8
|
|
|
{ |
9
|
|
|
name: 'author', |
10
|
|
|
email: '[email protected]' |
11
|
|
|
} |
12
|
|
|
], |
13
|
|
|
contributors: [ |
14
|
|
|
{ |
15
|
|
|
name: 'contributor', |
16
|
|
|
email: '[email protected]' |
17
|
|
|
} |
18
|
|
|
], |
19
|
|
|
categories: [ |
20
|
|
|
{ |
21
|
|
|
scheme: 'scheme', |
22
|
|
|
term: 'term', |
23
|
|
|
label: 'label' |
24
|
|
|
} |
25
|
|
|
], |
26
|
|
|
generator: { |
27
|
|
|
uri: 'uri', |
28
|
|
|
version: 'version', |
29
|
|
|
value: 'value' |
30
|
|
|
}, |
31
|
|
|
icon: 'icon', |
32
|
|
|
id: 'id', |
33
|
|
|
links: { |
34
|
|
|
rel: { |
35
|
|
|
href: 'href' |
36
|
|
|
} |
37
|
|
|
}, |
38
|
|
|
logo: 'logo', |
39
|
|
|
rights: 'rights', |
40
|
|
|
subtitle: 'subtitle', |
41
|
|
|
title: 'title', |
42
|
|
|
updated: 123456789, |
43
|
|
|
content: { |
44
|
|
|
gedcomx: { |
45
|
|
|
description: '#root' |
46
|
|
|
} |
47
|
|
|
}, |
48
|
|
|
confidence: 4, |
49
|
|
|
published: 123456780, |
50
|
|
|
source: { |
51
|
|
|
logo: 'logo', |
52
|
|
|
rights: 'rights', |
53
|
|
|
subtitle: 'subtitle' |
54
|
|
|
}, |
55
|
|
|
summary: 'summary', |
56
|
|
|
score: 122.32 |
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
it('Create plain', function(){ |
60
|
|
|
assert.instanceOf(new GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor with new.'); |
61
|
|
|
assert.instanceOf(GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor without new.'); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
it('Create with JSON', function(){ |
65
|
|
|
tests(GedcomX.AtomEntry(json)); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
it('Build', function(){ |
69
|
|
|
tests(GedcomX.AtomEntry() |
70
|
|
|
.addAuthor( |
71
|
|
|
GedcomX.AtomPerson() |
72
|
|
|
.setName('author') |
73
|
|
|
.setEmail('[email protected]') |
74
|
|
|
) |
75
|
|
|
.addContributor( |
76
|
|
|
GedcomX.AtomPerson() |
77
|
|
|
.setName('contributor') |
78
|
|
|
.setEmail('[email protected]') |
79
|
|
|
) |
80
|
|
|
.addCategory( |
81
|
|
|
GedcomX.AtomCategory() |
82
|
|
|
.setScheme('scheme') |
83
|
|
|
.setTerm('term') |
84
|
|
|
.setLabel('label') |
85
|
|
|
) |
86
|
|
|
.setGenerator( |
87
|
|
|
GedcomX.AtomGenerator() |
88
|
|
|
.setUri('uri') |
89
|
|
|
.setVersion('version') |
90
|
|
|
.setValue('value') |
91
|
|
|
) |
92
|
|
|
.setIcon('icon') |
93
|
|
|
.setId('id') |
94
|
|
|
.addLink( |
95
|
|
|
GedcomX.Link() |
96
|
|
|
.setRel('rel') |
97
|
|
|
.setHref('href') |
98
|
|
|
) |
99
|
|
|
.setLogo('logo') |
100
|
|
|
.setRights('rights') |
101
|
|
|
.setSubtitle('subtitle') |
102
|
|
|
.setTitle('title') |
103
|
|
|
.setUpdated(123456789) |
104
|
|
|
.setConfidence(4) |
105
|
|
|
.setPublished(123456780) |
106
|
|
|
.setSummary('summary') |
107
|
|
|
.setScore(122.32) |
108
|
|
|
.setContent({ |
109
|
|
|
gedcomx: { |
110
|
|
|
description: '#root' |
111
|
|
|
} |
112
|
|
|
}) |
113
|
|
|
.setSource({ |
114
|
|
|
logo: 'logo', |
115
|
|
|
rights: 'rights', |
116
|
|
|
subtitle: 'subtitle' |
117
|
|
|
}) |
118
|
|
|
); |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
it('toJSON', function(){ |
122
|
|
|
assert.deepEqual(GedcomX.AtomEntry(json).toJSON(), json); |
123
|
|
|
}); |
124
|
|
|
|
125
|
|
|
it('constructor does not copy instances', function(){ |
126
|
|
|
var obj1 = GedcomX.AtomEntry(); |
127
|
|
|
var obj2 = GedcomX.AtomEntry(obj1); |
128
|
|
|
assert.strictEqual(obj1, obj2); |
129
|
|
|
}); |
130
|
|
|
|
131
|
|
|
}); |
132
|
|
|
|
133
|
|
|
function tests(entry){ |
134
|
|
|
assert.equal(entry.getAuthors().length, 1); |
135
|
|
|
var author = entry.getAuthors()[0]; |
136
|
|
|
assert.equal(author.getName(), 'author'); |
137
|
|
|
assert.equal(author.getEmail(), '[email protected]'); |
138
|
|
|
|
139
|
|
|
assert.equal(entry.getContributors().length, 1); |
140
|
|
|
var contributor = entry.getContributors()[0]; |
141
|
|
|
assert.equal(contributor.getName(), 'contributor'); |
142
|
|
|
assert.equal(contributor.getEmail(), '[email protected]'); |
143
|
|
|
|
144
|
|
|
assert.equal(entry.getCategories().length, 1); |
145
|
|
|
var category = entry.getCategories()[0]; |
146
|
|
|
assert.equal(category.getScheme(), 'scheme'); |
147
|
|
|
assert.equal(category.getTerm(), 'term'); |
148
|
|
|
assert.equal(category.getLabel(), 'label'); |
149
|
|
|
|
150
|
|
|
var generator = entry.getGenerator(); |
151
|
|
|
assert.equal(generator.getUri(), 'uri'); |
152
|
|
|
assert.equal(generator.getVersion(), 'version'); |
153
|
|
|
assert.equal(generator.getValue(), 'value'); |
154
|
|
|
|
155
|
|
|
assert.equal(entry.getIcon(), 'icon'); |
156
|
|
|
assert.equal(entry.getId(), 'id'); |
157
|
|
|
assert.equal(entry.getLinks().length, 1); |
158
|
|
|
assert.equal(entry.getLink('rel').getHref(), 'href'); |
159
|
|
|
assert.equal(entry.getLogo(), 'logo'); |
160
|
|
|
assert.equal(entry.getRights(), 'rights'); |
161
|
|
|
assert.equal(entry.getSubtitle(), 'subtitle'); |
162
|
|
|
assert.equal(entry.getTitle(), 'title'); |
163
|
|
|
assert.equal(entry.getUpdated().getTime(), 123456789); |
164
|
|
|
assert.equal(entry.getConfidence(), 4); |
165
|
|
|
assert.equal(entry.getPublished().getTime(), 123456780); |
166
|
|
|
assert.equal(entry.getSummary(), 'summary'); |
167
|
|
|
assert.equal(entry.getScore(), 122.32); |
168
|
|
|
|
169
|
|
|
var content = entry.getContent(); |
170
|
|
|
assert.equal(content.getGedcomX().getDescription(), '#root'); |
171
|
|
|
|
172
|
|
|
var source = entry.getSource(); |
173
|
|
|
assert.equal(source.getLogo(), 'logo'); |
174
|
|
|
assert.equal(source.getRights(), 'rights'); |
175
|
|
|
assert.equal(source.getSubtitle(), 'subtitle'); |
176
|
|
|
} |